<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>JavaScript 函数</h1>

    <h2>箭头函数</h2>

    <p>这个例子展示了箭头函数的语法，以及如何使用它。</p>

    <script>
        let myFunction = (a, b) => a * b;

        let myFunction1 = function (a, b) {
            return a * b;
        };

        document.write(myFunction(4, 4));
        document.write("<br>");
        document.write(myFunction1(4, 4));

        hello1 = function () {
            return "Hello World!";
        }
        hello2 = () => {
            return "Hello World!";
        }
        hello3 = () => "Hello World!";
        document.write("<br>");
        document.write(hello1());
        document.write("<br>");
        document.write(hello2());
        document.write("<br>");
        document.write(hello3());

        hello4 = (val) => "Hello " + val;
        hello5 = val => "Hello " + val;
        document.write("<br>");
        document.write(hello4("World"));
        document.write("<br>");
        document.write(hello5("JavaScript"));

        //对于箭头函数，this 关键字始终表示定义箭头函数的对象。
        //用了箭头函数，则 this 表示函数的拥有者
    </script>
</body>

</html>